<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>忘记密码</title>
    <link rel="stylesheet" href="../public/dist/css/layui.css">
    <link rel="stylesheet" href="../public/font/iconfont.css">
    <link rel="stylesheet" href="../css/forget.css">

</head>

<body>
    <div class="logo">供应链协同管理平台</div>
    <div class="head">
        设置新密码
    </div>
    <div class="input" id="jump1">
        <div class="item">
            <div class="item-txt">
                企业名称:
            </div>
            <input type="text" placeholder="请输入您的企业名称" class="layui-input" id="qiye">
        </div>

        <div class="item">
            <div class="item-txt">
                用户名称:
            </div>
            <input type="text" placeholder="请输入您的用户名称" class="layui-input" id="yong">
        </div>

        <div class="item">
            <div class="item-txt">
                手机号:
            </div>
            <input type="text" placeholder="请输入您的手机号码" class="layui-input " id="ph">
        </div>

        <div class="item">
            <div class="item-txt">
                验证码:
            </div>

            <input type="text" placeholder="请输入您的验证码" class="layui-input" id="yen">

            <button class="buts">
                      获取验证码
           </button>
        </div>


        <div class="btns">
            <div class="btns-item" id="login">返回登录</div>
            <div class="btns-item" id='jump-2'>下一步</div>
        </div>
    </div>

    <div class="input" id="jump2" style="display:none">
        <div class="item">
            <div class="item-txt">
                新密码:
            </div>
            <input type="text" placeholder="请输入您的新密码" class="layui-input" id="news">
        </div>
        <div class="item">
            <div class="item-txt">
                确认密码:
            </div>
            <input type="password" placeholder="请输入您的确认密码" class="layui-input" id="olds">
        </div>
        <div class="btns">
            <div class="btns-item" id="jump-1">上一步</div>
            <div class="btns-item" id="jump-3">下一步</div>
        </div>
    </div>

    <div id="jump3" style="display:none">
        <div class="input-s">
            <i class="layui-icon layui-icon-face-smile" style="font-size: 30px; color: #1E9FFF;"></i> 已完成!
        </div>

        <div class="btns">
            <div class="btns-item" id="jump-2s">上一步</div>
            <div class="btns-item">完成</div>
        </div>
    </div>
</body>
<script src="../public/dist/layui.js" charset="utf-8"></script>
<script src="../js/forget.js" charset="utf-8"></script>
<script src="../js/common/jquery.min.js"></script>
<script src="../js/common/api.js"></script>

</html>
<script type="text/javascript">
    layui.use(["layer", "form"], function() {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

        //验证码
        //发送
        var tims = null;
        var numss = 60;
        $(".buts").click(function() {

            if ($("#ph").val() == "") {
                layer.msg("请输入手机号", {
                    offset: "200",
                    time: 800,
                });
                return
            }
            if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test($("#ph").val()))) {
                layer.msg('请输入正确手机号', {
                    offset: "200",
                    time: 1000,
                });
                $("#ph").val("");
                return false;
            }
            var thenss = $(this);
            $(this).attr("disabled", true);
            tims = setInterval(function() {
                numss--;
                thenss.text(numss + "s");
                if (numss == 0) {
                    clearInterval(tims);
                    thenss.text("发送");
                    numss = 60;
                    thenss.removeAttr("disabled");
                }
            }, 1000);


            noAjax("coRegisterInvi/sendCode", {
                phone: $("#ph").val(),
            }, "post").done(function(resp) {
                console.log(resp)
                layer.msg(resp.message, {
                    offset: "200",
                    time: 1000,
                });
                return
            }).fail(function(err) {
                console.log(err)
            });
            return
        })

        //返回登录
        $("#login").click(function() {
            window.location.href = "./login.html";
        })

        //下一页
        $("#jump-2").click(function() {
            if ($("#qiye").val() == "") {
                layer.msg("请输入企业名称", {
                    offset: "200",
                    time: 800,
                });
                return
            }
            if ($("#yong").val() == "") {
                layer.msg("请输入用户名称", {
                    offset: "200",
                    time: 800,
                });
                return
            }
            if ($("#ph").val() == "") {
                layer.msg("请输入手机号", {
                    offset: "200",
                    time: 800,
                });
                return
            }
            if ($("#yen").val() == "") {
                layer.msg("请输入验证码", {
                    offset: "200",
                    time: 800,
                });
                return
            }

            noAjax("coRegisterInvi/checkSmsCode", {
                phone: $("#ph").val(),
                smscode: $("#yen").val()
            }, "get").done(function(resp) {
                console.log(resp)
                if (resp.code == 10000) {
                    setTimeout(function() {
                        $("#jump1").css("display", "none");
                        $("#jump2").css("display", "block");
                    }, 1500)

                }
                layer.msg(resp.message, {
                    offset: "200",
                    time: 1000,
                });
                return
            }).fail(function(err) {
                console.log(err)
            });
            return
        })

        //上一页
        $("#jump-1").click(function() {
            $("#jump1").css("display", "block");
            $("#jump2").css("display", "none");
        })

        //下一页2
        $("#jump-3").click(function() {
            if ($("#news").val() == "") {
                layer.msg("请输入新密码", {
                    offset: "200",
                    time: 800,
                });
                return
            }
            if ($("#olds").val() != $("#news").val()) {
                layer.msg("确认密码不正确", {
                    offset: "200",
                    time: 800,
                });
                return
            }

            noAjax("coRegisterInvi/updatePassword", {
                enterpriseName: $("#qiye").val(),
                username: $("#yong").val(),
                phone: $("#ph").val(),
                newPassword: $("#news").val()
            }, "post").done(function(resp) {
                console.log(resp)
                if (resp.code == 10000) {
                    setTimeout(function() {
                        $("#jump1").css("display", "none");
                        $("#jump2").css("display", "none");
                        $("#jump3").css("display", "block");
                    }, 1500)
                }
                layer.msg(resp.message, {
                    offset: "200",
                    time: 1000,
                });
                return
            }).fail(function(err) {
                console.log(err)
            });
        })

        $("#jump-2s").click(function() {
            $("#jump1").css("display", "none");
            $("#jump2").css("display", "block");
            $("#jump3").css("display", "none");
        })

    })
</script>